<?php
import('Database.~');

abstract class AGestion{

	protected $table;
	private $db;
	protected $dataPost;

	public function __construct(){
		$this->db = Hoa_Database_Dal::getInstance('myConn');
	}

	public function add($data){
		$dataInsert = '\' \','; // Définition de l'id
		foreach($data as $key => $val){
			$dataInsert .= '\''.$val.'\', ';
		}
		$dataInsert = substr($dataInsert, 0, strlen($dataInsert)-2); // Suppression des 2 derniers caractères
		$requete = 'INSERT INTO '.$this->table.' VALUES('.$dataInsert.')';
		$statement = null;
		try {
			$statement = $this->db->query($requete);
		}
		catch ( Hoa_Database_Dal_Exception $e ) {
			$e->raiseError();
		}
		self::removeCache();
	}
	public function update(){
		try {
			$this->fram->db->query('UPDATE FROM '.$this->nameInBase.' SET '.$newValue.' WHERE id = '.$param['id']);
		} catch ( Hoa_Database_Dal_Exception $e ) {
			$e->raiseError();
		}
	}
	public function delete($id){
		try {
			$this->db->beginTransaction();
			$this->db->query('DELETE FROM '.$this->table.' WHERE id = '.$id);
			$this->db->commit();
			self::removeCache();
		} catch ( Hoa_Database_Dal_Exception $e ) {
			$this->db->rollBack();
			$e->raiseError();
		}
	}

	private function removeCache(){
		import('Cache.~');
		$frontendOptions = array(
			'lifetime' => 600
		);
		$backendOptions = array(
			'cache_directory' => '_Cache/'
		);
		$cache = Hoa_Cache::factory('Output', 'File', $frontendOptions, $backendOptions);
		$cache->clean(Hoa_Cache::CLEANING_ALL);
	}
}


?>